import java.util.Arrays;
import java.util.HashMap;

public class t953 {
    //验证外星语词典
    public static void main(String[] args) {

        String arr[] = {"apple","app"};
        String s = "abcdefghijklmnopqrstuvwxyz";
        boolean f = isAlienSorted(arr, s);
        System.out.println(f);
    }

    public static boolean isAlienSorted(String[] words, String order) {
        HashMap<String, Integer> map = new HashMap<>();
        for (int i = 0; i < 26; i++) {
            map.put(order.substring(i, i + 1), i);
        }
        int len = 0;
        for (int i = 0; i < words.length; i++) {
            len = Math.max(len, words[i].length());
        }
        String arr[] = new String[words.length];
       aa: for(int i =0;i<len;i++){
            for(int j = 0;j<words.length;j++){
                if(i<=words[j].length()-1)arr[j] = words[j].substring(i,i+1);
            }
            System.out.println(Arrays.toString(arr));
            int k =0;
            int lens = 0;
            for(int j = 0;j<words.length-1;j++){

                if(arr[j] != null && arr[j+1]==null){
                   return false;
                }
                if(arr[j]==null && (arr[j+1]!=null || arr[j+1]==null)){
                    continue aa;
                }
                if(map.get(arr[j]) > map.get(arr[j+1])){
                    return false;
                }
                if(map.get(arr[j]) < map.get(arr[j+1])){
                    k++;
                }
                lens++;

            }
            if(k == lens){
                return true;
            }
           arr = new String[words.length];
        }
        return true;
    }


}
